﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace XiaoYou.XuzhouZhihuiYinshui.Migrations
{
    public partial class init_waterquality_v1 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AppWaterQualityStations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppWaterQualityStations", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AppWaterQualityDatas",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Current = table.Column<double>(type: "double", nullable: false),
                    Min = table.Column<double>(type: "double", nullable: false),
                    Max = table.Column<double>(type: "double", nullable: false),
                    Name = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    WaterQulityStationId = table.Column<int>(type: "int", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    WaterQualityStationId = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppWaterQualityDatas", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppWaterQualityDatas_AppWaterQualityStations_WaterQualitySta~",
                        column: x => x.WaterQualityStationId,
                        principalTable: "AppWaterQualityStations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AppWaterQualityHistories",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Value = table.Column<double>(type: "double", nullable: false),
                    WaterQualityDataId = table.Column<int>(type: "int", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppWaterQualityHistories", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppWaterQualityHistories_AppWaterQualityDatas_WaterQualityDa~",
                        column: x => x.WaterQualityDataId,
                        principalTable: "AppWaterQualityDatas",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_AppWaterQualityDatas_WaterQualityStationId",
                table: "AppWaterQualityDatas",
                column: "WaterQualityStationId");

            migrationBuilder.CreateIndex(
                name: "IX_AppWaterQualityHistories_WaterQualityDataId",
                table: "AppWaterQualityHistories",
                column: "WaterQualityDataId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AppWaterQualityHistories");

            migrationBuilder.DropTable(
                name: "AppWaterQualityDatas");

            migrationBuilder.DropTable(
                name: "AppWaterQualityStations");
        }
    }
}
